package com.lykj.llw.box.adapter.home

import android.view.View
import android.widget.TextView
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lykj.lib_base.component.GlideApp
import com.lykj.llw.box.R
import com.lykj.llw.box.data.bean.response.HomeResponse

/**
 * ================================================
 * 排行榜游戏列表适配器
 * ================================================
 *
 * @author gosha
 * @date 2023/10/19-14:59
 */
class HomeTopGameAdapter :
    BaseQuickAdapter<HomeResponse.DataDTO.SortGameListDTO, BaseViewHolder>(R.layout.item_top_game) {
    override fun convert(holder: BaseViewHolder, item: HomeResponse.DataDTO.SortGameListDTO) {
        holder.setText(R.id.tv_role_name, "${item.gamename}")
        holder.setText(R.id.tv_summery, "${item.subject}")

        GlideApp.with(context)
            .load(item.icon)
            .transition(DrawableTransitionOptions.withCrossFade())
            .into(holder.getView(R.id.iv_icon))

        holder.getView<TextView>(R.id.tv_discount).visibility =
            if (item.payRatio == 0.01) View.VISIBLE else View.GONE

        when (holder.layoutPosition) {
            0 -> {
                holder.setBackgroundResource(R.id.clt_root, R.mipmap.bg_top_1)
            }

            1 -> {
                holder.setBackgroundResource(R.id.clt_root, R.mipmap.bg_top_2)
            }

            2 -> {
                holder.setBackgroundResource(R.id.clt_root, R.mipmap.bg_top_3)
            }

            3 -> {
                holder.setBackgroundResource(R.id.clt_root, R.mipmap.bg_top_4)
            }

            4 -> {
                holder.setBackgroundResource(R.id.clt_root, R.mipmap.bg_top_5)
            }

            5 -> {
                holder.setBackgroundResource(R.id.clt_root, R.mipmap.bg_top_6)
            }
        }
    }
}